//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    // manageList:[
    //     {
    //       icon:"../../img/home_icon1.png",
    //       title:"患者管理",
    //       list:[
    //         {img:"../../img/home_img1.png",name:"患者报道",url:"/hyb_yl/doctorHome/pages/patientlist/patientlist"},
    //         {img:"../../img/home_img2.png",name:"患者分组",url:""},
    //         {img:"../../img/home_img3.png",name:"患者随访",url:"/hyb_yl/doctorHome/pages/result_task/result_task"},
    //         {img:"../../img/home_img4.png",name:"患者签约",url:"/hyb_yl/doctorHome/pages/patientlist/patientlist"},
    //       ]
    //     },
    //     {
    //       icon:"../../img/home_icon2.png",
    //       title:"订单管理",
    //       list:[
    //         {img:"../../img/home_img5.png",name:"接诊大厅",url:"/hyb_yl/lvtongserver/pages/docorder/docorder"},
    //         {img:"../../img/home_img6.png",name:"问诊管理",url:""},
    //         {img:"../../img/home_img7.png",name:"挂号管理",url:"/hyb_yl/mysubpages/pages/serviceList/serviceList"},
    //         {img:"../../img/home_img8.png",name:"开方管理",url:"/hyb_yl/mysubpages/pages/docorder/docorder"},
    //       ]
    //     },
    //     {
    //       icon:"../../img/home_icon3.png",
    //       title:"工具管理",
    //       list:[
    //         {img:"../../img/home_img9.png",name:"服务包管理",url:"/hyb_yl/mysubpages/pages/openservice/openservice"},
    //         {img:"../../img/home_img10.png",name:"电子签名",url:""},
    //         {img:"../../img/home_img11.png",name:"年卡管理",url:"/hyb_yl/zhuanjiasubpages/pages/cover/cover"},
    //         {img:"../../img/home_img12.png",name:"医嘱记录",url:"/hyb_yl/zhuanjiasubpages/pages/chufangjilu/chufangjilu"},
    //         {img:"../../img/home_img13.png",name:"审核处方",url:""},
    //       ]
    //     },
        
    // ],
    zid:"",
  },
  toorder:function(e){
    // titlme=电话咨询&key_words=dianhuajizhen&id=22&zid=34&z_telephone=18303588513
    var titlme = e.currentTarget.dataset.titlme;
    var key_words = e.currentTarget.dataset.key_words;
    if(key_words == 'tijianjiedu' || key_words == 'yuanchengguahao' || key_words == 'shoushukuaiyue')
    {
      wx.navigateTo({
        
        url: '/hyb_yl/mysubpages/pages/serviceList/serviceList?keyword='+e.currentTarget.dataset.key_words+'&titlme='+e.currentTarget.dataset.titlme+'&id='+e.currentTarget.dataset.id+'&zid='+e.currentTarget.dataset.zid+'&z_telephone='+e.currentTarget.dataset.z_telephone+'&key_words='+e.currentTarget.dataset.key_words,
      })
    }else if(key_words == 'suifang'){
      wx.navigateTo({
        
        url: '/hyb_yl/doctorHome/pages/order_lists/order_lists?zid='+e.currentTarget.dataset.zid,
      })
    }else
    {
      wx.navigateTo({
        url: '/hyb_yl/mysubpages/pages/docorder/docorder?keyword='+e.currentTarget.dataset.key_words+'&titlme='+e.currentTarget.dataset.titlme+'&id='+e.currentTarget.dataset.id+'&zid='+e.currentTarget.dataset.zid+'&z_telephone='+e.currentTarget.dataset.z_telephone+'&key_words='+e.currentTarget.dataset.key_words,
      })
    }
    
  },
  // 工作管理跳转页面
  go_back:function(e){
    var that = this;
    var url=e.currentTarget.dataset.url
    console.log(url);
    if(url == '/hyb_yl/mysubpages/pages/serviceList/serviceList')
    {
      wx.navigateTo({
        url: url+'?keyword=yuanchengguahao&titlme=在线挂号&zid='+this.data.zid+'&z_telephone='+this.data.docinfo.z_telephone,
      })
    }else if(url == '/hyb_yl/mysubpages/pages/docorder/docorder')
    {
      wx.navigateTo({
        url: '/hyb_yl/mysubpages/pages/docorder/docorder?keyword=yuanchengkaifang&titlme=在线开方&zid='+this.data.zid+'&z_telephone='+this.data.docinfo.z_telephone,
      })
    }else if(url == 'saoma'){
      wx.scanCode({
        success:function(re){
          console.log(re)
          var data = re.path;
          var tids = data.split("=");
          var tid = tids[1];
          app.util.request({
            'url':"entry/wxapp/team.add_teams",
            data:{
              y_openid:wx.getStorageSync('openid'),
              y_zid:that.data.zid,
              tid:tid,
            },
            success:function(res)
            {
              wx.showToast({
                title: res.data.message,
              })
            }
          })
        }
      })
    }else{
      wx.navigateTo({
        url: url+'?zid='+this.data.zid,
      })
    }
  },
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
    var that = this;
    that.getZhuanjia();
    that.getMenu();
  },
  // 获取专家详情
  getZhuanjia:function(){
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/studio.ifzhuanjia',
      data: {
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        var zid = res.data.zid
        wx.setStorageSync('zid', zid)
        var z_telephone = res.data.z_telephone
        that.setData({
          docinfo: res.data,
          zid: res.data.zid,
          data_list: res.data.data_list,
        })
        that.bangdingtel(zid, z_telephone)
      }
    })
  },
  // 获取菜单列表
  getMenu:function(){
    var that = this;
    console.log('111');
    app.util.request({
      'url': "entry/wxapp/user.getcenter",
      data: {
        type: 1
      },
      success: function (res) {
        console.log(res)
        that.setData({
          server: res.data,
        })
      },
      fail:function(re)
      {
        console.log('222')
      }
    })
  },
  bangdingtel(zid, z_telephone) {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/yuyue.telcotime',
      data: {
        doc_phone: that.data.z_telephone,
        zid: that.data.zid
      },
      success: function (res) {
        console.log(res, privateNum)
        //更新聊天电话
        if (res.data !== 1) {
          if (res.data.privateNum == undefined || res.data.privateNum == 'undefined') {
            var privateNum = ''
          } else {
            var privateNum = res.data.privateNum
          }
          app.util.request({
            url: 'entry/wxapp/yuyue.upcharmsg',
            data: {
              zid: that.data.zid,
              privateNum: privateNum
            },
            success: function (res) {
              console.log(res)
            }
          })
        }

      }
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
